#include <avz.h>
#include "sin20_tools.h"

using namespace cresc;
using namespace sin20;
using namespace AvZ;

void Script()
{
    OpenMultipleEffective('Q', AvZ::MAIN_UI_OR_FIGHT_UI); // 多次生效
    GetMainObject()->seedArray()->count() = 10;           // 10 卡槽
    SetAdvancedPauseKey('Z');                             // 按 Z 键控制高级暂停

    SetZombies({
        ZOMBIE,
        POLE_VAULTING_ZOMBIE,
        FOOTBALL_ZOMBIE,
        DANCING_ZOMBIE,
        ZOMBONI,
        JACK_IN_THE_BOX_ZOMBIE,
        DIGGER_ZOMBIE,
        POGO_ZOMBIE,
        BUNGEE_ZOMBIE,
        LADDER_ZOMBIE,
        CATAPULT_ZOMBIE,
        GARGANTUAR,
        GIGA_GARGANTUAR,
        DOLPHIN_RIDER_ZOMBIE,
        SNORKEL_ZOMBIE,
    });
    BungeeManipulate(3, 6, {20}); // 蹦极位置

    SelectCards({
        ICE_SHROOM,
        M_ICE_SHROOM,
        COFFEE_BEAN,
        DOOM_SHROOM,
        CHERRY_BOMB,
        LILY_PAD,
        JALAPENO,
        SCAREDY_SHROOM,
        PUFF_SHROOM,
        FLOWER_POT,
    });

    /*
    w1: N/PSN 601 （3-8存冰）（4-9 N）
    w2: Pd/PAD 601
    w3: IP-cc-PP 1375
    w4: I3PD-cc-PP 1433
    w5: I3PD+b-cc-PP 1433
    w6: I3PD-cc-PP 1433
    w7: I3PD-cc-PP 1433
    w8: I3PD+b-cc-PP 1433
    w9: I3PD-cc-AN/PND-d/P-（3-8 N）

    w10: N/PSN+A' 601（3-9 N）
    w11: Pd/PAD 601
    w12: IP-cc-PP 1375
    w13: I3PD-cc-PP 1433
    w14: I3PD+b-cc-PP 1433
    w15: I3PD-cc-PP 1433
    w16: I3PD-cc-PP 1433
    w17: I3PD+b-cc-PP 1433
    w18: I3PD-cc-PP 1433
    w19: I3PD-cc-P/PAD-P-Pd
    */

    SetTime(-599, 1);
    pao_operator.autoGetPaoList();
    ice_filler.start({{3, 6}, {4, 7}, {4, 8}, {3, 7}, {3, 8}});
    Card(LILY_PAD, 4, 9);
    AvZ::MaidCheats::dancing();

    for (auto wave : {1, 10})
    {
        // N/PSNcc(+A') 601
        SetTime(290 - 373, wave);
        pao_operator.pao({{5, 9}, {5, 9}}); // PS 290
        SetTime(401 - 298);
        SetPlantActiveTime(DOOM_SHROOM, 298);
        if (wave == 1)
        {
            Card({{DOOM_SHROOM, 4, 9}, {COFFEE_BEAN, 4, 9}});
        }
        else
        {
            Card({{LILY_PAD, 3, 9}, {DOOM_SHROOM, 3, 9}, {COFFEE_BEAN, 3, 9}}); // N 401
        }

        if (wave == 10)
        {
            SetTime(-200);
            ice_filler.resetFillList({{3, 6}, {4, 7}, {4, 8}});
            SetTime(294);
            Card(JALAPENO, 3, 7);
        } // A'
    }

    for (auto wave : {2, 11})
    {
        // Pd/BAD 601
        SetTime(318 - 373, wave);
        pao_operator.pao(2, 9); // 上半场P 318
        SetTime(225 - 373);
        pao_operator.pao(5, 9); // 下半场P 225
        Delay(110);
        pao_operator.pao(5, 8.8); // D
        SetTime(226 - 100);
        Card(CHERRY_BOMB, 5, 9); // A 226
        SetTime(579 - 373);
        pao_operator.pao(1, 3); // d 579(318+264-3)

        SetTime(602 - 298);
        SetPlantActiveTime(ICE_SHROOM, 298);
        ice_filler.coffee(); // 下波预判冰
    }

    for (auto wave : {3, 12})
    {
        // IP-cc-PP 1375
        SetTime(-95, wave);
        pao_operator.pao(5, 9); // 热过渡P
        SetTime(1175 - 373);
        pao_operator.pao({{2, 8.6}, {5, 8.5125}}); // PP

        SetTime(1175 - 266 - 1);
        Card({{PUFF_SHROOM, 5, 9}, {FLOWER_POT, 6, 9}}); // cc 1175-266-1
        Delay(266);
        Shovel({{5, 9}, {6, 9}});

        SetTime(1375 + 10 - 298);
        SetPlantActiveTime(ICE_SHROOM, 298);
        ice_filler.coffee(); // 下波I3
    }

    for (auto wave : {4, 6, 7, 13, 15, 16, 18})
    {
        // I3PD-cc-PP 1433
        SetTime(411 - 373, wave);
        pao_operator.pao(5, 8.4625); // P 411
        Delay(212);
        pao_operator.pao(5, 8.5875); // D
        SetTime(1233 - 373);
        pao_operator.pao({{2, 8.525}, {5, 8.4375}}); // PP 1233

        SetTime(1233 - 266 - 1);
        Card({{PUFF_SHROOM, 5, 9}, {FLOWER_POT, 6, 9}}); // cc 1233-266-1
        Delay(266);
        Shovel({{5, 9}, {6, 9}});

        SetTime(1433 + 10 - 298);
        SetPlantActiveTime(ICE_SHROOM, 298);
        ice_filler.coffee(); // 下波I3
    }

    for (auto wave : {5, 8, 14, 17})
    {
        // I3PD+b-cc-PP 1433
        SetTime(411 - 373, wave);
        pao_operator.pao({{5, 8.4625}, {1, 1.5}}); // P、b 411
        Delay(212);
        pao_operator.pao(5, 8.5875); // D
        SetTime(1233 - 373);
        pao_operator.pao({{2, 8.525}, {5, 8.4375}}); // PP 1233

        SetTime(1233 - 266 - 1);
        Card({{PUFF_SHROOM, 5, 9}, {FLOWER_POT, 6, 9}}); // cc 1233-266-1
        Delay(266);
        Shovel({{5, 9}, {6, 9}});

        SetTime(1433 + 10 - 298);
        SetPlantActiveTime(ICE_SHROOM, 298);
        ice_filler.coffee(); // 下波I3
    }

    for (auto wave : {9})
    {
        // I3PD-cc-AN/PND-d/P-（3-8 N）
        SetTime(-200, wave);
        Card({{LILY_PAD, 3, 8}, {DOOM_SHROOM, 3, 8}});

        SetTime(411 - 373, wave);
        pao_operator.pao(5, 8.4625); // P 411
        Delay(212);
        pao_operator.pao(5, 8.5875); // D

        SetTime(1233 - 414 - 1);
        Card({{PUFF_SHROOM, 5, 9}, {FLOWER_POT, 6, 9}}); // cc 1232-414-1
        Delay(266);
        Shovel({{5, 9}, {6, 9}});

        SetTime(712 - 100);
        Card({{LILY_PAD, 3, 9}, {CHERRY_BOMB, 3, 9}}); // A严谨收小丑（最早712全收）
        SetTime(1233 - 373);
        pao_operator.pao(5, 8.525); // P 1233
        SetTime(1233 - 298);
        SetPlantActiveTime(DOOM_SHROOM, 298);
        Card(COFFEE_BEAN, 3, 8); // N 1233
        SetTime(1233 + 220 - 373);
        pao_operator.pao(5, 8.475); // D

        SetTime(1333 + 220 + 360 - 373);
        pao_operator.recoverPao({{1, 1.5}, {5, 9}}); // d/P
        SetTime(2453 - 373);
        pao_operator.pao(1, 8.5); // P
        Delay(110);
        pao_operator.pao(1, 7.15);     // D
        pao_operator.recoverPao(1, 1); // d 收上一d可能漏的小鬼

        SetTime(4300 - 373);
        pao_operator.pao(1, 5);
    }

    for (auto wave : {19})
    {
        // I3PD-cc-P/PAD
        SetTime(411 - 373, wave);
        pao_operator.pao(5, 8.4625); // P 411
        Delay(212);
        pao_operator.pao(5, 8.5875); // D

        SetTime(1039 - 414 - 1);
        Card({{PUFF_SHROOM, 5, 9}, {FLOWER_POT, 6, 9}}); // cc 1039-414-1
        Delay(266);
        Shovel({{5, 9}, {6, 9}});

        SetTime(1039 - 373);
        pao_operator.pao({{2, 9}, {5, 9}}); // PP 1039
        SetTime(1039);
        Card(CHERRY_BOMB, 5, 9); // A
        SetTime(1139 + 220 - 373);
        pao_operator.pao(5, 8.4875); // D

        pao_operator.recoverPao({{2, 9}, {1, 1.5}, {5, 9}, {1, 2}, {2, 8.5}});
        SetTime(2000);
        Card({{PUFF_SHROOM, 5, 9}, {FLOWER_POT, 6, 9}});
        Delay(100);
        Shovel({{5, 9}, {6, 9}});
    }

    SetTime(-200, 20);
    AvZ::MaidCheats::move();
    SetTime(900);
    AvZ::MaidCheats::dancing();
    SetTime(-150);
    pao_operator.pao(4, 7.5875);
    SetTime(737 - 3 - 373);
    pao_operator.pao(2, 3);
    SetTime(-55);
    pao_operator.pao({{5, 9}, {5, 9}});
    Delay(110);
    pao_operator.pao({{5, 8.8}});
    SetTime(813 - 373);
    pao_operator.pao({{5, 9}});
    SetTime(705 - 373);
    pao_operator.pao({{2, 8.175}});
    Delay(122);
    pao_operator.pao({{1, 7}});
    pao_operator.recoverPao({{1, 1}});
    SetTime(737);
    Card(LILY_PAD, 3, 8);

    // 存冰位调整
    SetTime(1500, 9);
    ice_filler.resetFillList({{3, 6}, {4, 7}, {4, 8}, {3, 8}});
    SetTime(295, 10);
    ice_filler.resetFillList({{3, 6}, {4, 7}, {4, 8}, {3, 7}, {3, 8}});
    SetTime(0, 19);
    ice_filler.resetFillList({{3, 7}, {4, 7}, {4, 8}});
    SetTime(0, 20);
    Card(PUFF_SHROOM, 3, 6);
    SetTime(758);
    ice_filler.resetFillList({{3, 6}, {3, 7}, {4, 7}, {4, 8}, {3, 8}});

    KeyConnect('P', [=]()
               { pao_operator.pao({{mouseRow(), mouseCol()}, {mouseRow(), mouseCol()}, {mouseRow(), mouseCol()}}); }); // 瞬杀一路红
}